<script type="text/javascript" src="__BT__/js/bootstrap.min.js"></script>
<script type="text/javascript" src="__JS__/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="__JS__/app.js"></script>
<script type="text/javascript" src="__JS__/php.js"></script>
<script type="text/javascript" src="__JS__/initPage.js"></script>
{include file="comm/confirm"/}
{if isset($KE) && $KE == "1"}
<script charset="utf-8" src="__KE__/kindeditor-all-min.js"></script>
<script charset="utf-8" src="__KE__/lang/zh-CN.js"></script>
{/if}
<script type="text/javascript">
    $(function () {
        /*var main = $(".main");
        main.css("width",((document.documentElement.clientWidth || window.innerWidth)-230)+"px");
        $(window).on("resize",function (e) {
            main.css("width",((document.documentElement.clientWidth || window.innerWidth)-230)+"px");
        });*/

        window.aEles=$("a");
        $("input[name=token]").val(LO.get("token",1));
        aEles.on("click",function (e) {
            var token = LO.get("token",1);
            var preg = /^javascript\:/i;
            var href="";
            if ((/^paginate_button/i).test(this.getAttribute("class"))){
                e.preventDefault();
                return false;
            }
            if( !preg.test( href = this.getAttribute("href")) ){
                e.preventDefault();
                (href == "/") && (href="");
                location.href=href+"/?token="+token;
            }

        });
    });

    var tID="myTable";
    var pageLength = parseInt(LO.get("pageLength",1),10);
    try {
        var _init_={};
        var myTable=$("#"+tID).DataTable( {
            "lengthMenu": [ 15 ,25 ,50 ,100 ,200 ,300 ,400 ,500],
            "pagingType": "full_numbers",
            //关闭排序
            "ordering": false,
            "drawCallback":function () {
                //set_myTable_tool();
                if (!_init_.ok) {
                    $(".dataTables_length select").attr("class","input-sm dt-select");
                    $(".dataTables_filter input").attr("class","inline dt-search");
                    _init_.ok = 1;
                }
            },
            "initComplete":function () {

            },
            "bSort": false,
            //设置每页显示的行数
            "pageLength": (typeof pageLength==="number") ? pageLength : 15 ,
            //语言配置
            "language":{
                // "decimal":        "",
                // "emptyTable":     "No data available in table",
                // "info":           "Showing _START_ to _END_ of _TOTAL_ entries",
                // "infoEmpty":      "Showing 0 to 0 of 0 entries",
                // "infoFiltered":   "(filtered from _MAX_ total entries)",
                // "infoPostFix":    "",
                // "thousands":      ",",
                // "lengthMenu":     "Show _MENU_ entries",
                // "loadingRecords": "Loading...",
                // "processing":     "Processing...",
                // "search":         "Search:",
                // "zeroRecords":    "No matching records found",
                // "paginate": {
                //     "first":      "First",
                //     "last":       "Last",
                //     "next":       "Next",
                //     "previous":   "Previous"
                // },
                // "aria": {
                //     "sortAscending":  ": activate to sort column ascending",
                //     "sortDescending": ": activate to sort column descending"
                // },
                "paginate":{
                    first: "首页",
                    previous: "上一页",
                    next: "下一页",
                    last: "尾页"
                },
                "lengthMenu":"每页 _MENU_ 条记录",
                "info":"显示 _START_ 到 _END_ 条，共 _TOTAL_ 条",
                "infoEmpty":"显示 0 到 _END_ 条，共 _TOTAL_ 条",
                "search":"查找：",
                "emptyTable":"暂无数据！",
            },


        });
        // set_myTable_tool();
        // function set_myTable_tool() {
        //     try {
        //         var info = myTable.page.info();
        //         $("#"+tID+"_info").html(
        //             "显示 "+(info.start+1)+" 到 "+(info.end)+" 条，共 "+(info.recordsTotal)+" 条"
        //         );
        //         $("#"+tID+"_first").html("首页");
        //         $("#"+tID+"_previous").html("上一页");
        //         $("#"+tID+"_next").html("下一页");
        //         $("#"+tID+"_last").html("尾页");
        //
        //         $("#"+tID+"_length").attr("class","col-sm-3");
        //         var label = $("#"+tID+"_length>label")[0];
        //         $("select",label).attr("class"," input-sm dt-select");
        //         label.childNodes[0].remove();
        //         label.childNodes[1].remove();
        //         label.childNodes[0].before("每页 ");
        //         label.childNodes[1].after(" 条记录");
        //         var filter = $("#"+tID+"_filter>label")[0];
        //         $("input",filter).attr("class","inline dt-search");
        //         filter.childNodes[0].remove();
        //         filter.childNodes[0].before("查找：");
        //
        //         $(".dataTables_empty").html("暂无数据！");
        //     }catch (e) {
        //
        //     }
        // }
        // function myTableSet(obj,t){
        //     var tID = "myTable";
        //     var info = obj.page.info();
        //     $("#"+tID+"_info").html(
        //         "显示 "+(info.start+1)+" 到 "+(info.end)+" 条，共 "+(info.recordsTotal)+" 条"
        //     );
        //     $("#"+tID+"_paginate").html();
        //
        //     if (t===1){
        //         $("#"+tID+"_next").on( 'click', function () {
        //             obj.page( 'next' ).draw( false );
        //             myTableSet(obj,0);
        //         } );
        //
        //         $("#"+tID+"_previous").on( "click", function () {
        //             obj.page( 'previous' ).draw( false );
        //         } );
        //     }
        //
        // }
        //myTableSet(myTable,1);

        $("#"+tID+"_length select").on("change",function (e) {
            LO.set("pageLength",this.value,1);
        });
    }catch (e) {

    }

</script>
{if $KE == "1"}
<script type="text/javascript">
    KindEditor.ready(function(K) {
        window.KE={};
        var editor = K.editor({
            allowFileManager : true
        });
        KE.K = K;
        KE.editor = editor;
        // K('#image2').click(function() {
        //     editor.loadPlugin('image', function() {
        //         editor.plugin.imageDialog({
        //             showLocal : false,
        //             imageUrl : K('#url2').val(),
        //             clickFn : function(url, title, width, height, border, align) {
        //                 K('#url2').val(url);
        //                 editor.hideDialog();
        //             }
        //         });
        //     });
        // });
        // K('#image3').click(function() {
        //     editor.loadPlugin('image', function() {
        //         editor.plugin.imageDialog({
        //             showRemote : false,
        //             imageUrl : K('#url3').val(),
        //             clickFn : function(url, title, width, height, border, align) {
        //                 K('#url3').val(url);
        //                 editor.hideDialog();
        //             }
        //         });
        //     });
        // });
    });

    $(function () {
        /*单张图片*/
        KE.K('#image_up_btn').click(function() {
            KE.editor.loadPlugin('image', function() {
                KE.editor.plugin.imageDialog({
                    imageUrl : "",
                    clickFn : function(url, title, width, height, border, align) {
                        var input_url = KE.K("#media_img");
                        input_url.val(url);
                        var img = KE.K("#img_value");
                        img.attr("src",url);
                        var img_preview = img.parent().parent();
                        img_preview.show();
                        var img_item = $(".s-div-img-item>i", img_preview);
                        img_item.unbind("click");
                        img_item.on("click",function (e) {
                            input_url.val("");
                            img.attr("src","");
                            $(this.parentNode.parentNode).hide();
                        });
                        KE.editor.hideDialog();
                    }
                });
            });
        });

        /*预览图片*/
        $("#images_up_btn,.images_up_btn").click(function (e) {
            try {
                var img_upload = this.parentNode;
                var img_preview = this.parentNode.parentNode.getElementsByTagName("div")[0];
            }catch (e) {

            }
            KE.editor.loadPlugin('image', function() {
                KE.editor.plugin.imageDialog({
                    imageUrl : "",
                    clickFn : function(url, title, width, height, border, align) {
                        var html = "<div class=\"s-div-img-item\" _src='"+url+"'>\n" +
                            "           <img src='"+url+"' >\n" +
                            "           <i class=\"fa fa-times\" aria-hidden=\"true\"></i>\n" +
                            "           <input type=\"hidden\"  name=\"meida_imgs[]\"  value='"+url+"'>\n" +
                            "       </div>";
                        if (img_preview) {
                            $(img_preview).append(html).show();
                        }
                        var img_item = $(".s-div-img-item>i",img_preview);
                        img_item.unbind('click');
                        img_item.on("click",function (e) {
                            $(this.parentNode).remove();
                            if ($(".s-div-img-item>i",img_preview).length<1){
                                $(img_preview).hide();
                            }
                        });
                        KE.editor.hideDialog();
                    }
                });
            });
        });


    });

    var KE_del = "{if $KEs.del == '1'}1{else}0{/if}";
    if (KE_del == "1") {
        Events.add(document,"click",function (e) {
            var e = e || window.event;
            var target = e.target || e.srcElement;
            //删除文件
            if (target.getAttribute("name") == "close_2019") {
                var img = $("div img",target.parentNode)[0];
                var path = img.getAttribute("src");
                confirms(0,{body:"确定要删除该文件吗？删除后将无法恢复"},function () {
                    clearTimeout(target.idd);
                    target.idd = setTimeout(function () {
                        $.post("__KE__/php/del_file.php",{path:path},function (data) {
                            data = JSON.parse(data);
                            console.log(data.code);
                            if (data.code == "1"){
                                tips_success("删除文件成功",function () {
                                    img.parentNode.parentNode.parentNode.removeChild(img.parentNode.parentNode);
                                });
                            }else{
                                tips_fail("删除文件失败");
                            }
                        });
                    },500);
                });
            }
        },true);
        Events.add(document,"mouseover",function (e) {
            var e = e || window.event;
            var target = e.target || e.srcElement;
            var href = target.getAttribute("_href");
            if (/(\.jpg$|\.png$|\.gif$|\.jpeg$|\.bmp$)/i.test(href)) {
                //alert("tupian");
                console.log(target.parentNode.parentNode.childNodes[0].className="");
            }
        },true);

    }

    //创建富文本编辑器
    function create_KE(select,C,fn) {
        (select) || (select="#media_content");
        (C) || (C = {});
        (C.height) || (C.height=500);
        (C.items) || (C.items=[
            'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
            'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
            'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
            'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
            'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
            'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', /*'multiimage',*/
            /*'flash',*/ /*'media',*/ 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
            'anchor', 'link', 'unlink', /*'|',*/ /*'about'*/
        ]);
        // 关闭过滤模式，保留所有标签
        (C.filterMode == "off" || C.filterMode === 0 )&&(KindEditor.options.filterMode = false);
        var config = {
            height:C.height,
            //显示图片空间
            allowFileManager:true,
            //编辑器创建时的回调函数
            afterCreate:function(){
                (typeof fn ==="function")&&fn.call(this,"afterCreate");
                /*粘贴图片功能，比如截图 start*/
                var editor = this;
                var editerDoc = this.edit.doc;//得到编辑器的文档对象
                //监听粘贴事件, 包括右键粘贴和ctrl+v
                $(editerDoc).bind('paste', null, function (e) {
                    /*获得操作系统剪切板里的项目，e即kindeditor,
                    *kindeditor创建了originalEvent(源事件)对象，
                    *并指向了浏览器的事件对象，而chrome浏览器
                    *需要通过clipboardData(剪贴板数据)对象的items
                    *获得复制的图片数据。
                    */
                    var ele = e.originalEvent.clipboardData.items;
                    for (var i = 0; i < ele.length; ++i) {
                        //判断文件类型
                        if (ele[i].kind == 'file' && ele[i].type.indexOf('image/') !== -1) {
                            var file = ele[i].getAsFile();//得到二进制数据
                            //创建表单对象，建立name=value的表单数据。
                            var formData = new FormData();
                            formData.append("imgFile", file);//name,value

                            //用jquery Ajax 上传二进制数据
                            $.ajax({
                                url: "__KE__/php/upload_json.php",
                                type: 'POST',
                                data: formData,
                                // 告诉jQuery不要去处理发送的数据
                                processData: false,
                                // 告诉jQuery不要去设置Content-Type请求头
                                contentType: false,
                                dataType: "json",
                                beforeSend: function () {
                                    //console.log("正在进行，请稍候");
                                },
                                success: function (responseStr) {
                                    //上传完之后，生成图片标签回显图片，假定服务器返回url。
                                    var src = responseStr.url;
                                    var imgTag = "<img src='" + src + "' border='0'/>";

                                    //console.info(imgTag);
                                    //kindeditor提供了一个在焦点位置插入HTML的函数，调用此函数即可。
                                    editor.insertHtml(imgTag);


                                },
                                error: function (responseStr) {
                                    console.log("error");
                                }
                            });
                        }
                    }
                });
                /*粘贴图片功能，比如截图 end*/
            },
            //编辑器内容发生变化后执行的回调函数
            afterChange:function () {
                //alert('abc');
                (typeof fn ==="function")&&fn.call(this,"afterChange");
            },
            //编辑器聚焦(focus)时执行的回调函数
            afterFocus:function (){
                (typeof fn ==="function")&&fn.call(this,"afterFocus");
            },
            //编辑器失去焦点(blur)时执行的回调函数
            afterBlur:function(){
                (typeof fn ==="function")&&fn.call(this,"afterBlur");
            },
            //上传文件后执行的回调函数
            afterUpload:function(){
                (typeof fn ==="function")&&fn.call(this,"afterUpload");
            },
            //从图片空间选择文件后执行的回调函数
            afterSelectFile:function () {
                (typeof fn ==="function")&&fn.call(this,"afterSelectFile");
            },
        };
        for (var attr in C){
            config[attr] = C[attr];
        }
        KindEditor.create(select,config);
    }
</script>
{/if}

<script type="text/javascript">
    function toTop() {
        move.move(document.body, {scrollTop:0},500,false,1);
        move.move(document.documentElement, {scrollTop:0},500,false,1);
    }
    Events.add(window,'scroll',function (e) {
        var target = Events.getTarget(e);
        var scrollTop = document.documentElement.scrollTop>0 ? document.documentElement.scrollTop : document.body.scrollTop;
        clearTimeout(document.idd2019);
        document.idd2019 = setTimeout(function () {
            if (scrollTop>=400){
                $(".s-toTop").attr("class","s-toTop");
            } else{
                $(".s-toTop").attr("class","s-toTop s-toTop-hide");
            }
        },300);
    },true);
</script>

<div class="s-toTop s-toTop-hide">
    <i class="fa  fa-angle-up" onclick="toTop()"></i>
</div>